

class Statistics {

  int count = 0;
  int[][] cells;
  float[][] ver;
  
  
  

  Statistics(int[][] table) {
    cells = table;
  }

  void read(){
    
    BufferedReader reader;
    float value;
    String line;
    boolean correct = true;
    
    reader = createReader("stat.bin");
    ver = new float[10][10];
    
    try {
      count = int(reader.readLine());
    } 
    catch (NullPointerException e) {
      e.printStackTrace();
      correct = false; 
    }
    catch (IOException e) {
      e.printStackTrace();
      correct = false; 
    }
    
    try{
      for (int i = 0 ; i < 10 ; i++){
        for (int j = 0 ; j < 10 ; j++){  
          ver[j][i] = float(reader.readLine());
        }
      }
    }
    catch (IOException e) {
      e.printStackTrace();
      correct = false; 
    }
    catch (NullPointerException e) {
      e.printStackTrace();
      correct = false; 
    }
    
    if(!correct){
      for (int i = 0 ; i < 10 ; i++){
        for (int j = 0 ; j < 10 ; j++){  
          ver[j][i] = 0;
          count = 0;
        }
      }
    }   

  }
  
  void calc(){
    int val;
    
    read();
    
    for (int i = 0 ; i < 10 ; i++){
        for (int j = 0 ; j < 10 ; j++){ 
          val = 0;
          if (cells[j][i] > 0){
            val = 1;
          }
          ver[j][i] = ((ver[j][i] * count) + val) / (count + 1);
        }
    }
    count = count + 1;
    write();
  }
  
  void write() {
    
    PrintWriter output;
    PrintWriter output2;
    output = createWriter("stat.bin"); 
    output2 = createWriter("stat2.bin");
    output.println(count);
    for (int i = 0 ; i < 10 ; i++){
      for (int j = 0 ; j < 10 ; j++){
        output.println(ver[j][i]);
        output2.println(ver[i][j]);
      }
    }
    output.flush(); 
    output.close();
    output2.flush(); 
    output2.close();
  }
  
  float getVer(int i, int j){
     return ver[j][i];
  }
}


